VB Sample Code for handling errors

Private Sub ErrorTrap(ByVal Source$, ByVal jobnum%)
Dim result%, errorcode%, textHandle&, TextLength%, ErrorText$

' Check for any error codes
errorcode% = PEGetErrorCode(jobnum%)
If errorcode% <> 0 Then
' If there is an error code, find out what it means
result% = PEGetErrorText(jobnum%, textHandle&, TextLength%)
If result% = 0 Then
' If getting the text failed, say so
ErrorText$ = "Error in ErrorTrap routine"
Else
' Get the text from the handle
ErrorText$ = String$(TextLength%, 0)
result% = crvbHandleToBstr(textHandle&, ErrorText$, TextLength%)
ErrorText$ = Trim$(ErrorText$)
ErrorText$ = Left$(ErrorText$, Len(ErrorText$) - 1)
End If
' Add source text to error text
ErrorText$ = Source$ & " caused an error: " & ErrorText$
' Display the message with an offer to terminate the program
If MsgBox(ErrorText$ & Chr$(10) & "Do you want to end the program?", vbYesNo + vbCritical, "An Error Has Occurred!") = vbYes Then
End
End If
End If
End Sub


ActiveX
Sub ErrorTrap(ByVal Source As String)
' Check for any error codes
If CrystalReport1.LastErrorNumber <> 0 Then
' If there is an error code, display the source of the error and error message with an offer to terminate the program
If MsgBox(Source & " caused an error: " & CrystalReport1.LastErrorString & Chr$(10) & "Do you want to end the program?", vbYesNo + vbCritical, "An Error Has Occurred!") = vbYes Then
End
End If
End If
End Sub


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com